package com.yu.yupicture.config;


import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

/**
 * 本地缓存 caffeine 配置
 */
@Configuration
public class CaffeineConfig {


    @Bean
    public Cache<String, Object> caffeineCache() {
        return  Caffeine.newBuilder()
                .initialCapacity(1000)
                .maximumSize(10000)
                .expireAfterWrite(Duration.of(10, ChronoUnit.MINUTES))
                .build();
    }
}
